#pragma once
#include "Asset.h"
#include <fstream>
#include <string>
#include "Binomial.h"

using namespace std;

class Option : Asset
{
public:

public:
	Option(void);
	~Option(void);
	void ValueOptions(char inName[], char outName[])
	{
		string type;
		double strick;
		double spot;
		double sigma;
		double t;
		double r;
		double price;

		ifstream fi(inName);
		ofstream fo(outName);
		Binomial binomal;
		while (fi.good())
		{
			fi >> type;
			fi >> strick;
			fi >> spot;
			fi >> sigma;
			fi >> t;
			fi >> r;

			if (type == "AC" || type == "ac")
			{
				
				price = binomal.CountS(50, spot, strick, r, sigma, t, 'C', 'A');
			}
			else
			{
				if (type == "AP" || type == "ap")
				{
					price = binomal.CountS(50, spot, strick, r, sigma, t, 'P', 'A');
				}
				else
				{
					if (type == "EC" || type == "ec")
					{
						price =  binomal.CountS(50, spot, strick, r, sigma, t, 'C', 'E');
					}
					else
					{
						price = binomal.CountS(50, spot, strick, r, sigma, t, 'P', 'E');
					}
				}
			}

			fo << type << " " << strick << " " << spot << " " << sigma << " " << t << " " << r << " " << price << "\n";
		}
	}

	void ValueDelta(char inName[], char outName[])
	{
		string type;
		double strike;
		double spot;
		double sigma;
		double t;
		double r;
		double price;
		double delta;

		ifstream fi(inName);
		ofstream fo(outName);
		Binomial binomial;
		while (!fi.eof())
		{
			fi >> type;
			fi >> strike;
			fi >> spot;
			fi >> sigma;
			fi >> t;
			fi >> r;

			if (type == "AC" || type == "ac")
			{
				price = binomial.CountS(50, spot, strike, r, sigma, t, 'C', 'A');
				double temp = binomial.generic_payoff( 'C', 'A', spot, strike);
				delta = binomial.option_price_delta_american_binomial('C','A', spot, strike , r, sigma, t, 50);
			}
			else
			{
				if (type == "AP" || type == "ap")
				{
					price = binomial.CountS(50, spot, strike, r, sigma, t, 'P', 'A');
					double temp = binomial.generic_payoff( 'P', 'A', spot, strike);
					delta = binomial.option_price_delta_american_binomial('P','A', spot, strike , r, sigma, t, 50);
				}
				else
				{
					if (type == "EC" || type == "ec")
					{
						price = binomial.CountS(50, spot, strike, r, sigma, t, 'C', 'E');
						double temp = binomial.generic_payoff( 'C', 'E', spot, strike);
						delta = binomial.option_price_delta_european_binomial('C','E', spot, strike , r, sigma, t, 50);
					}
					else
					{
						price = binomial.CountS(50, spot, strike, r, sigma, t, 'P', 'E');
						double temp = binomial.generic_payoff( 'P', 'E', spot, strike);
						delta = binomial.option_price_delta_european_binomial('P','E', spot, strike , r, sigma, t, 50);
					}
				}
			}

			fo << type << " " << strike << " " << spot << " " << sigma << " " << t << " " << r << " " << price << " " << delta << "\n";
		}
	}
};

